﻿package  
{
	import com.event.EventZheng;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author zhengzihua
	 */
	public class BallAndLine extends Sprite
	{
		private var _line:Sprite;
		private var _ball:Ball;
		private var _isLevel1:Boolean = false;
		public function BallAndLine() 
		{
			_line = new Sprite();
			_ball = new Ball();
			_ball.addEventListener(StaticInfo.MOVEBALL, onMoveBall);
			_ball.addEventListener(StaticInfo.STOPBALL, onMoveBall);
		}
		private function onMoveBall(e:EventZheng):void 
		{
			var ep:Point = e.obj.ep;
			if (!isLevel1) {
				drawLine(ep);
			}
		}
		//ball从父级菜单处指向子级菜单
		public function createBallAndLine(ep:Point):void {
			addChild(_line);
			addChild(_ball);
			ball.moveBall(new Point(0, 0), ep);
		}
		//ball在同级之间移动
		public function moveBallAndLine(sp:Point,ep:Point):void {
			ball.moveBall(sp, ep);
		}
		//删除自己
		public function delThis():void {
			_ball.removeEventListener(StaticInfo.MOVEBALL, onMoveBall);
			_ball.removeEventListener(StaticInfo.STOPBALL, onMoveBall);
			if(_line.parent!=null){
				removeChild(_line);
			}
			if(_ball.parent!=null){
				removeChild(_ball);
			}
			parent.removeChild(this);
		}
		public function stopMoveBall():void {
			ball.stopBall();
		}
		private function drawLine(ep:Point):void {
			_line.graphics.clear();
			_line.graphics.lineStyle(StaticInfo.LINE_THICKNESS,StaticInfo.LINE_COLOR,0.5);
			_line.graphics.moveTo(0, 0);
			_line.graphics.lineTo(ep.x, ep.y);
		}
		public function get line():Sprite { return _line; }
		
		public function get ball():Ball { return _ball; }
		
		public function set ball(value:Ball):void 
		{
			_ball = value;
		}
		
		public function set line(value:Sprite):void 
		{
			_line = value;
		}
		
		public function get isLevel1():Boolean { return _isLevel1; }
		
		public function set isLevel1(value:Boolean):void 
		{
			_isLevel1 = value;
		}
	}
	
}